package org.arkeologgr.appening.domain;

import java.util.ArrayList;
import java.util.List;

import com.google.android.maps.GeoPoint;

public class CultureItem {
	
	public static final String ID = "item_id";
	
	private String id;
	private String description ="";
	private String title = "";
	private GeoPoint geoPoint;
	private CultureItemType type;
	private String thumbUrl ="";
	private String owner;
	
	
	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	private List<Comment> mComments;
	
	private List<String>tags;
	
	private long commentCount;
	

	public CultureItem(){
		mComments = new ArrayList<Comment>();
	}

	public CultureItem(String id, String description, GeoPoint geoPoint,
			CultureItemType type, String thumbUrl, String title
			) {
		super();
		this.id = id;
		this.description = description;
		this.geoPoint = geoPoint;
		this.type = type;
		this.thumbUrl = thumbUrl;
		this.title = title;
		
	}
	
	public CultureItem(String id, String description, GeoPoint geoPoint,
			CultureItemType type, String thumbUrl, String title
			, String owner, List<Comment> mComments, List<String> tags,
			long commentCount, String imageUrl
			) {
		super();
		this.id = id;
		this.description = description;
		this.geoPoint = geoPoint;
		this.type = type;
		this.thumbUrl = thumbUrl;
		this.title = title;
		this.owner = owner;
		this.mComments = mComments;
		this.tags = tags;
		this.commentCount = commentCount;
		this.imageUrl = imageUrl;
	}
	
	/*
	public CultureItem(String id, String description, String title,
			GeoPoint geoPoint, CultureItemType type, String thumbUrl,
			String owner, List<Comment> mComments, List<String> tags,
			long commentCount, String imageUrl) {
		super();
		this.id = id;
		this.description = description;
		this.title = title;
		this.geoPoint = geoPoint;
		this.type = type;
		this.thumbUrl = thumbUrl;
		this.owner = owner;
		this.mComments = mComments;
		this.tags = tags;
		this.commentCount = commentCount;
		this.imageUrl = imageUrl;
	}*/
	
	public CultureItem(CultureItemType type, GeoPoint point){
		this.type = type;
		this.geoPoint = point;
	}
	
	public GeoPoint getGeoPoint(){
		return geoPoint;
	}
	
	public CultureItemType getType(){
		return type;
	}

	public void setGeoPoint(double lat, double lgn) {
		GeoPoint gepoint = new GeoPoint((int)(lat * 1E6) , (int)(lgn * 1E6));
		setGeoPoint(gepoint);
	}

	public void setGeoPoint(GeoPoint geoPoint) {
		this.geoPoint = geoPoint;
	}

	
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getId() {
		return id;
	}

	public void setType(CultureItemType type) {
		this.type = type;
	}
	
	public void setType(String type){
		//String type = obj.getString("itemSource");
		if(type.equals("Internal")){
			setType(CultureItemType.UserGeneratedItem);
		} else if(type.equals("KSam")){
			setType(CultureItemType.KSamItemType);
		} else {
			throw new RuntimeException("Error finding ItemSource");
		}
	}

	public void setId(String id) {
		this.id = id;		
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getThumbUrl() {
		return thumbUrl;
	}

	public void setThumbUrl(String thumbUrl) {
		this.thumbUrl = thumbUrl;
	}
	
	public void setThumbUrl(String thumbUrl, boolean removeSpacing){
		if(thumbUrl != null && removeSpacing){
			setThumbUrl(thumbUrl.replaceAll(" ", "%20"));
		}else{
			setThumbUrl(thumbUrl);
		}
	}
	
	public List<String> getTags() {
		return tags;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public long getCommentCount() {
		return commentCount;
	}
	
	public double getLatitude(){
		return ((double)(getGeoPoint().getLatitudeE6())/(1000*1000));
	}

	public double getLongitude(){
		return ((double)(getGeoPoint().getLongitudeE6())/(1000*1000));
	}
	
	public void setCommentCount(long commentCount) {
		this.commentCount = commentCount;
	}
	
	public void addComment(String title, String text) {
		mComments.add(new Comment(title, text));
		commentCount = mComments.size();
	}
	
	public List<Comment> getComments() {
		return mComments;
	}
	private String imageUrl;
	public void setImageUrl(String optString) {
		imageUrl = optString;
	}
	
	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl, boolean removeSpacing) {
		if(imageUrl != null && removeSpacing){
			setImageUrl(imageUrl.replaceAll(" ", "%20"));
		}else{
			setImageUrl(imageUrl);
		}
		
	}

}
